package com.emagic.manage.data.db.entry;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;
import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.ToOne;

/**
 * 设备类型
 * Created by xiatian on 2017/8/14.
 */

@Entity
public class DeviceType {

    //服务端唯一标识(row_id)，父级类型标识(category_id)，类型编码(code)，类型名称(name)，缩略图(pic)，备注(remark)
    @Id
    private Long rowId;
    private Long categoryId;
    private String code;
    private String name;
    private String picPath;
    private String remark;
    private String typeName;

    @ToOne(joinProperty = "categoryId")
    private DeviceType parent;

    @ToMany(referencedJoinProperty = "categoryId")
    private List<DeviceType> deviceTypes;

    @ToMany(referencedJoinProperty = "typeId")
    private List<InspectItem> inspectItems;

    @ToMany(referencedJoinProperty =  "typeId")
    private List<MaintainItem> maintainItems;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 675724437)
    private transient DeviceTypeDao myDao;
    @Generated(hash = 1293412156)
    private transient Long parent__resolvedKey;

    @Generated(hash = 2003001116)
    public DeviceType(Long rowId, Long categoryId, String code, String name,
            String picPath, String remark, String typeName) {
        this.rowId = rowId;
        this.categoryId = categoryId;
        this.code = code;
        this.name = name;
        this.picPath = picPath;
        this.remark = remark;
        this.typeName = typeName;
    }

    @Generated(hash = 1621062569)
    public DeviceType() {
    }

    public Long getRowId() {
        return this.rowId;
    }

    public void setRowId(Long rowId) {
        this.rowId = rowId;
    }

    public Long getCategoryId() {
        return this.categoryId;
    }

    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPicPath() {
        return this.picPath;
    }

    public void setPicPath(String picPath) {
        this.picPath = picPath;
    }

    public String getRemark() {
        return this.remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getTypeName() {
        return this.typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1896743143)
    public List<DeviceType> getDeviceTypes() {
        if (deviceTypes == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            DeviceTypeDao targetDao = daoSession.getDeviceTypeDao();
            List<DeviceType> deviceTypesNew = targetDao
                    ._queryDeviceType_DeviceTypes(rowId);
            synchronized (this) {
                if (deviceTypes == null) {
                    deviceTypes = deviceTypesNew;
                }
            }
        }
        return deviceTypes;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1334479316)
    public synchronized void resetDeviceTypes() {
        deviceTypes = null;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1155671022)
    public List<InspectItem> getInspectItems() {
        if (inspectItems == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            InspectItemDao targetDao = daoSession.getInspectItemDao();
            List<InspectItem> inspectItemsNew = targetDao
                    ._queryDeviceType_InspectItems(rowId);
            synchronized (this) {
                if (inspectItems == null) {
                    inspectItems = inspectItemsNew;
                }
            }
        }
        return inspectItems;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1918839725)
    public synchronized void resetInspectItems() {
        inspectItems = null;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1608929517)
    public List<MaintainItem> getMaintainItems() {
        if (maintainItems == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            MaintainItemDao targetDao = daoSession.getMaintainItemDao();
            List<MaintainItem> maintainItemsNew = targetDao
                    ._queryDeviceType_MaintainItems(rowId);
            synchronized (this) {
                if (maintainItems == null) {
                    maintainItems = maintainItemsNew;
                }
            }
        }
        return maintainItems;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1185388881)
    public synchronized void resetMaintainItems() {
        maintainItems = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 1761564935)
    public DeviceType getParent() {
        Long __key = this.categoryId;
        if (parent__resolvedKey == null || !parent__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            DeviceTypeDao targetDao = daoSession.getDeviceTypeDao();
            DeviceType parentNew = targetDao.load(__key);
            synchronized (this) {
                parent = parentNew;
                parent__resolvedKey = __key;
            }
        }
        return parent;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 2065055714)
    public void setParent(DeviceType parent) {
        synchronized (this) {
            this.parent = parent;
            categoryId = parent == null ? null : parent.getRowId();
            parent__resolvedKey = categoryId;
        }
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 592604696)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getDeviceTypeDao() : null;
    }



}
